package com.zttek.videoShareProject.modules.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.zttek.videoShareProject.modules.model.User;
import com.zttek.videoShareProject.modules.mapper.UserMapper;
import com.zttek.videoShareProject.modules.service.IUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CBY
 * @since 2018-07-03
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Autowired UserMapper userMapper;
    @Override
    public User selectUserById(Long userid) throws Exception {
        User user = userMapper.selectById(userid);
        return user;
    }

    @Override
    public User selectUserByAccount(String account)  {
        EntityWrapper<User> ew = new EntityWrapper<>();
        ew.eq("account",account);
        List<User> list = userMapper.selectList(ew);
        if (list.size()>0){
            return list.get(0);
        }else return null;

    }

    @Override
    public List<User> selectUserList(int pageNum) throws Exception {
        EntityWrapper <User> wrapper=new EntityWrapper<>();
        wrapper.eq("status",0);
        Page<User> userPage=new Page<>();
        userPage.setSize(10);
        userPage.setAsc(false);
        userPage.setCurrent(pageNum);
        userPage.setOrderByField("create_date");
         List<User> list=userMapper.selectPage(userPage,wrapper);
            if(list.size()>0){
                return list;
            }else
         return null;
    }



}
